package org.example.commonapi.dto;

import com.baomidou.mybatisplus.annotation.TableId;
import io.jsonwebtoken.Claims;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.commonapi.domain.User;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginInfo {

    /**
     * 用户ID
     */
    @TableId
    private Long id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 权限
     */
    private Integer role;

    /**
     * 头像链接
     */
    private String headerLink;


    /**
     * User转换
     * @param user
     */
    public LoginInfo(User user) {
        this.username=user.getUsername();
        this.password=user.getPassword();
        this.role=user.getRole();
        this.id=user.getId();
    }

    /**
     * token提取信息
     * @param claims
     */
    public LoginInfo(Claims claims) {
        this.id=claims.get("id", Long.class);
    }

}
